package com.twoGroup.boot.utils;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.twoGroup.boot.config.PropertiesConfig;
import com.twoGroup.boot.pojo.AlipayBean;


/**
 * @ClassName
 * @Description TODO
 * @Author Xuyujie
 * @Date 2021/5/12 11:31
 * @Version 1.0
 **/
public class AlipayUtil {
    public static String connect(AlipayBean alipayBean) throws AlipayApiException {
        //1����ó�ʼ����AlipayClient
        AlipayClient alipayClient = new DefaultAlipayClient(
                PropertiesConfig.getKey("gatewayUrl"),//֧��������
                PropertiesConfig.getKey("app_id"),//appid
                PropertiesConfig.getKey("merchant_private_key"),//�̻�˽Կ
                "json", PropertiesConfig.getKey("charset"),//�ַ������ʽ
                PropertiesConfig.getKey("alipay_public_key"),//֧������Կ
                PropertiesConfig.getKey("sign_type")//ǩ����ʽ
        );
//2�������������
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
//ҳ����תͬ��֪ͨҳ��·��
        alipayRequest.setReturnUrl(PropertiesConfig.getKey("return_url"));
// �������첽֪ͨҳ��·��
        alipayRequest.setNotifyUrl(PropertiesConfig.getKey("notify_url"));
//��װ����
        alipayRequest.setBizContent(JSON.toJSONString(alipayBean));
//3������֧�������и������ȡ֧�����
        String result = alipayClient.pageExecute(alipayRequest).getBody();
//���ظ�����Ϣ
        return result;
    }
}
